/**
 * 
 */
package au.edu.swin.videoshop.posapp.ui.sections;

import java.io.Serializable;
import java.util.Map;

import javax.ejb.EJB;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import au.edu.swin.videoshop.bean.Staff;
import au.edu.swin.videoshop.service.StaffService;

public class UserSection implements Serializable {
	private String mUserName;
	private String mPassword;
	private Staff mStaff;
	
	@EJB
	private StaffService mStaffService;
	
	public UserSection() {
	}
	
	public Staff getStaff() {
		return mStaff;
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return mUserName;
	}

	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		mUserName = userName;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return mPassword;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		mPassword = password;
	}

	public String login() {
		mStaff = mStaffService.login(mUserName, mPassword);
		mUserName = null;
		mPassword = null;
		return null;
	}
	
	public String logout() {
		mStaffService.logout(mStaff);
		 
		FacesContext context = FacesContext.getCurrentInstance();
 		ExternalContext ec = context.getExternalContext();
 
 		HttpServletRequest request = (HttpServletRequest)ec.getRequest();
 	    request.getSession( false ).invalidate();
 	  
 	     
	     return "logout";
	}
}



